﻿

using System.Linq;
using MinesV1;
using NUnit.Framework;

namespace TestMinesV1
{
    [TestFixture]
    public class MinesV1Tests
    {
        [Test]
        public void Test1()
        {
            string[] stringInput = {"    ", 
                                    "  * ", 
                                    "    "};

            var minesBoard = MinesSolver.CreateBooleanBoard(stringInput);
            var playBoard = MinesSolver.CreatePlayBoard(minesBoard);

            var expected1 = new int[,]  {{ 0, 0, 0, 0, 0, 0 }, 
                                         { 0, 0, 1, 1, 1, 0 }, 
                                         { 0, 0, 1, 0, 1, 0 }, 
                                         { 0, 0, 1, 1, 1, 0 }, 
                                         { 0, 0, 0, 0, 0, 0 }};

            Assert.That(playBoard, Is.EqualTo(expected1));

            string[] expected2 = { "0111", 
                                   "0101", 
                                   "0111" };
                
            var stringOutput = MinesSolver.PlayBoardToString(playBoard);

            Assert.That(stringOutput, Is.EqualTo(expected2));
        }

        [Test]
        public void Test2()
        {
            string[] stringInput = { "*    ", 
                                     "     ", 
                                     "     " };

            var minesBoard = MinesSolver.CreateBooleanBoard(stringInput);
            var playBoard = MinesSolver.CreatePlayBoard(minesBoard);

            var expected1 = new int[,]
                                {   {1, 1, 1, 0, 0, 0, 0}, 
                                    {1, 0, 1, 0, 0, 0, 0}, 
                                    {1, 1, 1, 0, 0, 0, 0},
                                    {0, 0, 0, 0, 0, 0, 0},
                                    {0, 0, 0, 0, 0, 0, 0}};

            Assert.That(playBoard, Is.EqualTo(expected1));

            string[] expected2 = { "01000", 
                                   "11000", 
                                   "00000" };

            var stringOutput = MinesSolver.PlayBoardToString(playBoard);

            Assert.That(stringOutput, Is.EqualTo(expected2));
        }


        [Test]
        public void Test3()
        {
            string[] stringInput = {"*  *", 
                                    "*  *", 
                                    "*  *"};

            var minesBoard = MinesSolver.CreateBooleanBoard(stringInput);
            var playBoard = MinesSolver.CreatePlayBoard(minesBoard);

            var expected1 = new int[,]  {{ 1, 1, 1, 1, 1, 1 }, 
                                         { 2, 1, 2, 2, 1, 2 }, 
                                         { 3, 2, 3, 3, 2, 3 }, 
                                         { 2, 1, 2, 2, 1, 2 }, 
                                         { 1, 1, 1, 1, 1, 1 }};

            Assert.That(playBoard, Is.EqualTo(expected1));

            string[] expected2 = { "1221", 
                                   "2332", 
                                   "1221"};

            var stringOutput = MinesSolver.PlayBoardToString(playBoard);
            Assert.That(stringOutput, Is.EqualTo(expected2));
        }

        [Test]
        public void Test4NoMines()
        {
            string[] stringInput = { " " };

            var minesBoard = MinesSolver.CreateBooleanBoard(stringInput);
            var playBoard = MinesSolver.CreatePlayBoard(minesBoard);

            var expected1 = new int[,]  {{ 0, 0, 0}, 
                                         { 0, 0, 0},
                                         { 0, 0, 0}};

            Assert.That(playBoard, Is.EqualTo(expected1));

            string[] expected2 = {"0"};

            var stringOutput = MinesSolver.PlayBoardToString(playBoard);
            Assert.That(stringOutput, Is.EqualTo(expected2));
        }

        [Test]
        public void Test4Mine()
        {
            string[] stringInput = { "*" };

            var minesBoard = MinesSolver.CreateBooleanBoard(stringInput);
            var playBoard = MinesSolver.CreatePlayBoard(minesBoard);

            var expected1 = new int[,]  {{ 1, 1, 1}, 
                                         { 1, 0, 1},
                                         { 1, 1, 1}};

            Assert.That(playBoard, Is.EqualTo(expected1));

            string[] expected2 = { "0" };

            var stringOutput = MinesSolver.PlayBoardToString(playBoard);
            Assert.That(stringOutput, Is.EqualTo(expected2));
        }

        [Test]
        public void Test5()
        {
            var minesBoard = new int[3, 4];
            minesBoard.Initialize();
            Assert.That(minesBoard.Length, Is.EqualTo(12));
            Assert.That(minesBoard.GetValue(1,1), Is.EqualTo(0));
        }

        [Test]
        public void Test6()
        {
            string[] stringInput = { "    ", 
                                     "  * ", 
                                     "    " };

            var numLines = stringInput.Length;
            var numColumns = stringInput.First().Length;
            Assert.That(numLines, Is.EqualTo(3));
            Assert.That(numColumns, Is.EqualTo(4));
            
        }

        [Test]
        public void Test7()
        {
            string[] stringInput = { "***", 
                                     "***", 
                                     "***" };

            string[] expected7 = { "353", 
                                   "585", 
                                   "353"};

            var stringOutput = MinesSolver.MineSearch(stringInput);
            Assert.That(stringOutput, Is.EqualTo(expected7));
        }


        [Test]
        public void Test8()
        {
            string[] stringInput = { "   ", 
                                     "   ", 
                                     "   " };

            string[] stringExpected = {  "000", 
                                         "000", 
                                         "000"};

            var stringOutput = MinesSolver.MineSearch(stringInput);

            Assert.That(stringOutput, Is.EqualTo(stringExpected));
        }

        [Test]
        public void Test9()
        {
            string[] stringInput = {"*****"};

            string[] stringExpected = {"12221"};

            var stringOutput = MinesSolver.MineSearch(stringInput);

            Assert.That(stringOutput, Is.EqualTo(stringExpected));
        }

        [Test]
        public void Test10()
        {
            string[] stringInput = { " ",
                                     " ",
                                     " "};

            string[] stringExpected = { "0",
                                        "0",
                                        "0",};

            var stringOutput = MinesSolver.MineSearch(stringInput);

            Assert.That(stringOutput, Is.EqualTo(stringExpected));
        }
        
    }
}
